package com.zrkizzy.seckill.vo.common;

import com.zrkizzy.seckill.enums.HttpStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 公共返回对象
 *
 * @author zhangrongkang
 * @since 2023/3/21
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 提示消息
     */
    private String message;

    /**
     * 携带数据
     */
    private Object data;

    /**
     * 成功返回结果
     */
    public static Result success() {
        return new Result(HttpStatusEnum.SUCCESS.getCode(),
                HttpStatusEnum.SUCCESS.getMessage(), null);
    }
    /**
     * 成功返回结果
     *
     * @param obj 携带数据
     */
    public static Result success(Object obj) {
        return new Result(HttpStatusEnum.SUCCESS.getCode(),
                HttpStatusEnum.SUCCESS.getMessage(), obj);
    }
    /**
     * 失败返回结果
     *
     * @param httpStatusEnum 状态枚举
     * @return 公共返回对象
     */
    public static Result error(HttpStatusEnum httpStatusEnum) {
        return new Result(httpStatusEnum.getCode(), httpStatusEnum.getMessage(), null);
    }

}
